

import { getFileType } from '@/plugin/utils/index'
import path from 'path'

import { message } from 'ant-design-vue';
import pImage from './pImage.vue'
import pPdf from './pPdf'
import pXlsx from './pXlsx'

const previewFile = (src = '', options = {}) => {

  src = src.replace(/[\[|\]|，|\,|#]/g, '') // 去除 # 等 浏览器 发出请求无法识别的 特殊 字符串
  const fileType = path.extname(src).substring(1)

  const type = getFileType(fileType)

  if( type == 'img' ){
    $g.createInstance(pImage, {
      src: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png?Authorization' + $g.getToken()
    })
  } else if ( fileType.toLowerCase() === 'xlsx' ) {
    $g.createInstance(pXlsx, {
      src: `http://192.168.3.63:38080/tnbs-filesystem/file/prod/files/202112/defaults/FDE4F47E1EF64C9F9F79D403C0BB7D33.xlsx?Authorization=${$g.getToken()}`
    })
  } else if (['doc', 'docx', 'pdf', 'xls'].includes(type)) {
    $g.createInstance(pPdf, {
      // src: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.pdf'
      src: `http://192.168.3.63:38080/tnbs-filesystem/file/prod/unzip/202112/7E3F0CAD28F64270BD61BBBAF4E96429/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E7%8E%B0%E7%8A%B6%E5%9B%BE.pdf?Authorization=${$g.getToken()}&type=1&content-type=application/octet-stream`
    })
  } else if (type === 'dwg') {
    createCompApi({
      comp: dwgPreview,
      data: {
        url: `${src}?Authorization=${getToken()}`
      }
    })
  } else {
    message.warning('暂不支持该文件格式预览')
  }

}

export default previewFile